{extend name="./indexmb" /}
{block name="setting_botton"}
<button type="button" onclick="data_group({{d.id}})" class="layui-btn layui-bg-blue layui-btn-sm upload">身份管理
</button>
<button type="button" onclick="data_upload({{d.id}})" class="layui-btn layui-bg-orange layui-btn-sm upload">编辑
</button>
{{# if(d.id !== 1) { }}
<button type="button" onclick="data_delete({{d.id}})" class="layui-btn layui-btn-sm layui-bg-red delete">删除
</button>
{{#} }}
{/block}
{block name="setting_all_botton"}
                    <div class="layui-inline">
                        <button class="layui-btn  layuiadmin-btn-useradmin layui-bg-red"
                            data-type="batchdel">批量删除</button>
                        <button class="layui-btn  layuiadmin-btn-useradmin layui-bg-blue" data-type="add">添加账号</button>
                    </div>
                    {/block}
{block name="js"}
<script>
    function data_group(id){
        layui.use('layer', function () {
            var $ = layui.$
                , table = layui.table
                , layer = layui.layer;
            layer.open({
                type: 2
                , title: '身份管理'
                , content: 'usergroup.html' + '?id=' + id
                , maxmin: true
                , area: ["500px", "350px"]
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                    var submitID = 'LAY-user-front-submit'
                    var submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        console.log(field);
                        // 提交 Ajax 成功后，静态更新表格中的数据
                        $.ajax({
                            'url': "{:url('user_group_ajax')}",
                            'method': 'POST',
                            'data': field,
                            'success': function (res) {
                                if (res.code == 200) {
                                    layer.msg('修改成功', {
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    }, function () {
                                        table.reload('demo');
                                    });
                                } else {
                                    layer.msg(res.message);
                                }
                            }
                        });
                        layer.close(index); //关闭弹层
                    });

                    submit.trigger('click');
                }
            });
        });
    }
</script>
{/block}